package com.tfyre.bambu.printer;

import java.util.Map;
import java.util.Optional;

/**
 *
 * @author Francois Steyn - (fsteyn@tfyre.co.za)
 */
public class BambuErrors {

    //Copied from https://github.com/xperiments-in/xtouch/blob/main/src/xtouch/bbl/bbl-errors.c
    //=CONCATENATE("Map.entry(""",SUBSTITUTE(B2,",",""),""",""",SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(C2,""",",""),"\""","\"),"\","\"""),""")")
    private static final Map<String, String> PRINTER_ERRORS = Map.ofEntries(
            Map.entry("12008007", "Failed to extrude the filament. The extruder may be clogged or the filament may be stuck, please refer to HMS. After troubleshooting, click \"Retry\" button."),
            Map.entry("12018007", "Failed to extrude the filament. The extruder may be clogged or the filament may be stuck, please refer to HMS. After troubleshooting, click \"Retry\" button."),
            Map.entry("12038007", "Failed to extrude the filament. The extruder may be clogged or the filament may be stuck, please refer to HMS. After troubleshooting, click \"Retry\" button."),
            Map.entry("12008016", "The extruder is not extruding normally, please refer to the HMS. After trouble shooting. If the defects are acceptable, please click \"Retry\" button."),
            Map.entry("12018016", "The extruder is not extruding normally, please refer to the HMS. After trouble shooting. If the defects are acceptable, please click \"Retry\" button."),
            Map.entry("12028016", "The extruder is not extruding normally, please refer to the HMS. After trouble shooting. If the defects are acceptable, please click \"Retry\" button."),
            Map.entry("12038016", "The extruder is not extruding normally, please refer to the HMS. After trouble shooting. If the defects are acceptable, please click \"Retry\" button."),
            Map.entry("12028007", "Failed to extrude the filament. The extruder may be clogged or the filament may be stuck, please refer to HMS. After troubleshooting, click \"Retry\" button."),
            Map.entry("03008014", "The nozzle is covered with filaments, or the build plate is installed incorrectly. Please cancel this printing and clean the nozzle or adjust the build plate according to the actual status, or tap \"Resume\" button to resume the print job."),
            Map.entry("03008016", "The nozzle is clogged up with filaments. Please cancel this printing and clean the nozzle according to the actual status, or tap \"Resume\" button to resume the print job."),
            Map.entry("03004005", "The nozzle fan speed is abnormal."),
            Map.entry("03008010", "The nozzle fan speed is abnormal."),
            Map.entry("0300400F", "No build plate is placed."),
            Map.entry("05014038", "The regional settings do not match the printer, please check the printer's regional settings."),
            Map.entry("05004002", "Unsupported print file path or name. Please resend the printing job."),
            Map.entry("03008017", "Foreign objects detected on  hotbed, Please check and clean the hotbed, Then tap \"Resume\" button to resume the print job."),
            Map.entry("05008036", "Your sliced file is not consistent with the current printer model. Continue?"),
            Map.entry("05004037", "Your sliced file is not compatible with current printer model. This file can't be printed on this printer."),
            Map.entry("05004038", "The nozzle diameter in sliced file is not consistent with the current nozzle setting. This file can't be printed."),
            Map.entry("1000C002", "Printing CF material with stainless steel may cause nozzle damage."),
            Map.entry("1000C003", "Enabling traditional timelapse might lead to defects. Continue?"),
            Map.entry("1001C001", "Timelapse is not supported because Spiral vase is enabled in slicing presets."),
            Map.entry("1001C002", "Timelapse is not supported because Print sequence is set to \"By object\"."),
            Map.entry("1000C001", "High bed temperature may lead to filament clogging in the nozzle. Please ensure ventilation for the printer."),
            Map.entry("05014035", "The device is in the process of binding and cannot respond to new binding requests."),
            Map.entry("03008015", "The filament has run out, please load new filament in the \"filament\" page, then return back to the print page and tap \"Resume\" to resume the print job."),
            Map.entry("05014032", "QR code binding is in progress, so device discovery binding cannot be performed. You can scan the QR code on the screen for binding or exit the QR code display page on screen and try device discovery binding."),
            Map.entry("05014033", "Your APP region is not matched with your printer, please download the APP in the corresponding region and register your account again."),
            Map.entry("12028005", "Failed to feed the filament. Please load the filament, then click the \"Retry\" button."),
            Map.entry("12038005", "Failed to feed the filament. Please load the filament, then click the \"Retry\" button."),
            Map.entry("12FF8005", "Failed to feed the filament. Please load the filament, then click the \"Retry\" button."),
            Map.entry("12028006", "Failed to feed the filament into the toolhead. Please check whether the filament is stuck. After troubleshooting, click the \"Retry\" button."),
            Map.entry("12038006", "Failed to feed the filament into the toolhead. Please check whether the filament is stuck. After troubleshooting, click the \"Retry\" button."),
            Map.entry("12FF8006", "Please feed from the spool holder until the tool head filament sensor is triggered, and then click the \"Retry\" button."),
            Map.entry("12028010", "Please check if the spool or filament is stuck. After troubleshooting, click the \"Retry\" button."),
            Map.entry("12038010", "Please check if the spool or filament is stuck. After troubleshooting, click the \"Retry\" button."),
            Map.entry("12FF8010", "Please check if the spool or filament is stuck. After troubleshooting, click the \"Retry\" button."),
            Map.entry("12028011", "AMS filament has run out. Please insert a new filament into the AMS and click the \"Retry\" button."),
            Map.entry("12038011", "AMS filament has run out. Please insert a new filament into the AMS and click the \"Retry\" button."),
            Map.entry("12FF8011", "AMS filament has run out. Please insert a new filament into the AMS and click the \"Retry\" button."),
            Map.entry("12028012", "Failed to get AMS mapping table; please click the \"Retry\" button to continue."),
            Map.entry("12038012", "Failed to get AMS mapping table; please click the \"Retry\" button to continue."),
            Map.entry("12FF8012", "Failed to get AMS mapping table; please click the \"Retry\" button to continue."),
            Map.entry("12028013", "Timeout while purging old filament. Please check if the filament is stuck or the extruder clogged. After troubleshooting, click the \"Retry\" button."),
            Map.entry("12038013", "Timeout while purging old filament. Please check if the filament is stuck or the extruder clogged. After troubleshooting, click the \"Retry\" button."),
            Map.entry("12FF8013", "Timeout while purging old filament. Please check if the filament is stuck or the extruder clogged. After troubleshooting, click the \"Retry\" button."),
            Map.entry("12028015", "Failed to pull back the filament from the toolhead. Please check if the filament is stuck or is broken inside the extruder. After troubleshooting, click the \"Retry\" button."),
            Map.entry("12038015", "Failed to pull back the filament from the toolhead. Please check if the filament is stuck or is broken inside the extruder. After troubleshooting, click the \"Retry\" button."),
            Map.entry("12038001", "Failed to cut the filament. Please check the cutter. After troubleshooting, click the \"Retry\" button."),
            Map.entry("12FF8001", "Failed to cut the filament. Please check the cutter. After troubleshooting, click the \"Retry\" button."),
            Map.entry("12038002", "The cutter is stuck. Please pull out the cutter handle and click the \"Retry\" button."),
            Map.entry("12FF8002", "The cutter is stuck. Please pull out the cutter handle and click the \"Retry\" button."),
            Map.entry("12038003", "Failed to pull out the filament from the extruder. Please check whether the extruder is clogged or whether the filament is broken inside the extruder. After troubleshooting, click the \"Retry\" button."),
            Map.entry("12028004", "Failed to pull back the filament from the toolhead. Please check whether the filament is stuck. After troubleshooting, click the \"Retry\" button."),
            Map.entry("12038004", "Failed to pull back the filament from the toolhead. Please check whether the filament is stuck. After troubleshooting, click the \"Retry\" button."),
            Map.entry("12FF8004", "Failed to pull back the filament from the toolhead. Please check whether the filament is stuck. After troubleshooting, click the \"Retry\" button."),
            Map.entry("07008001", "Failed to cut the filament. Please check the cutter. After troubleshooting, click the \"Retry\" button."),
            Map.entry("07008002", "The cutter is stuck. Please pull out the cutter handle and click the \"Retry\" button."),
            Map.entry("07008003", "Failed to pull out the filament from the extruder. Please check whether the extruder is clogged or whether the filament is broken inside the extruder. After troubleshooting, click the \"Retry\" button."),
            Map.entry("07008004", "Failed to pull back the filament from the toolhead to AMS. Please check whether the filament or the spool is stuck. After troubleshooting, click the \"Retry\" button."),
            Map.entry("07008005", "Failed to feed the filament outside the AMS. Please clip the end of the filament flat and check to see if the spool is stuck. After troubleshooting, click the \"Retry\" button."),
            Map.entry("07008006", "Failed to feed the filament into the toolhead. Please check whether the filament or the spool is stuck. After troubleshooting, click the \"Retry\" button."),
            Map.entry("07008007", "Failed to extrude the filament. Please check if the extruder is clogged. After troubleshooting, click the \"Retry\" button."),
            Map.entry("07008010", "AMS assist motor is overloaded. Please check if the spool or filament is stuck. After troubleshooting, click the \"Retry\" button."),
            Map.entry("07008011", "AMS filament ran out. Please put a new filament into AMS and click the \"Retry\" button."),
            Map.entry("07018001", "Failed to cut the filament. Please check the cutter. After troubleshooting, click the \"Retry\" button."),
            Map.entry("07018002", "The cutter is stuck. Please pull out the cutter handle and click the \"Retry\" button."),
            Map.entry("07018003", "Failed to pull out the filament from the extruder. Please check whether the extruder is clogged or whether the filament is broken inside the extruder. After troubleshooting, click the \"Retry\" button."),
            Map.entry("07018004", "Failed to pull back the filament from the toolhead to AMS. Please check whether the filament or the spool is stuck. After troubleshooting, click the \"Retry\" button."),
            Map.entry("07018005", "Failed to feed the filament outside the AMS. Please clip the end of the filament flat and check to see if the spool is stuck. After troubleshooting, click the \"Retry\" button."),
            Map.entry("07018006", "Failed to feed the filament into the toolhead. Please check whether the filament or the spool is stuck. After troubleshooting, click the \"Retry\" button."),
            Map.entry("07018007", "Failed to extrude the filament. Please check if the extruder clogged. After troubleshooting, click the \"Retry\" button."),
            Map.entry("07018010", "AMS assist motor is overloaded. Please check if the spool or filament is stuck. After troubleshooting, click the \"Retry\" button."),
            Map.entry("07018011", "AMS filament ran out. Please put a new filament into AMS and click the \"Retry\" button."),
            Map.entry("07028001", "Failed to cut the filament. Please check the cutter. After troubleshooting, click the \"Retry\" button."),
            Map.entry("07028002", "The cutter is stuck. Please pull out the cutter handle and click the \"Retry\" button."),
            Map.entry("07028003", "Failed to pull out the filament from the extruder. Please check whether the extruder is clogged or whether the filament is broken inside the extruder. After troubleshooting, click the \"Retry\" button."),
            Map.entry("07028004", "Failed to pull back the filament from the toolhead to AMS. Please check whether the filament or the spool is stuck. After troubleshooting, click the \"Retry\" button."),
            Map.entry("07028005", "Failed to feed the filament outside the AMS. Please clip the end of the filament flat and check to see if the spool is stuck. After troubleshooting, click the \"Retry\" button."),
            Map.entry("07028006", "Failed to feed the filament into the toolhead. Please check whether the filament or the spool is stuck. After troubleshooting, click the \"Retry\" button."),
            Map.entry("07028007", "Failed to extrude the filament. Please check if the extruder clogged. After troubleshooting, click the \"Retry\" button."),
            Map.entry("07028010", "AMS assist motor is overloaded. Please check if the spool or filament is stuck. After troubleshooting, click the \"Retry\" button."),
            Map.entry("07028011", "AMS filament ran out. Please put a new filament into AMS and click the \"Retry\" button."),
            Map.entry("07038001", "Failed to cut the filament. Please check the cutter. After troubleshooting, click the \"Retry\" button."),
            Map.entry("07038002", "The cutter is stuck. Please pull out the cutter handle and click the \"Retry\" button."),
            Map.entry("07038003", "Failed to pull out the filament from the extruder. Please check whether the extruder is clogged or whether the filament is broken inside the extruder. After troubleshooting, click the \"Retry\" button."),
            Map.entry("07038004", "Failed to pull back the filament from the toolhead to AMS. Please check whether the filament or the spool is stuck. After troubleshooting, click the \"Retry\" button."),
            Map.entry("07038005", "Failed to feed the filament outside the AMS. Please clip the end of the filament flat and check to see if the spool is stuck. After troubleshooting, click the \"Retry\" button."),
            Map.entry("07038006", "Failed to feed the filament into the toolhead. Please check whether the filament or the spool is stuck. After troubleshooting, click the \"Retry\" button."),
            Map.entry("07038007", "Failed to extrude the filament. Please check if the extruder clogged. After troubleshooting, click the \"Retry\" button."),
            Map.entry("07038010", "AMS assist motor is overloaded. Please check if the spool or filament is stuck. After troubleshooting, click the \"Retry\" button."),
            Map.entry("07038011", "AMS filament ran out. Please put a new filament into AMS and click the \"Retry\" button."),
            Map.entry("07008013", "Timeout purging old filament: Please check if the filament is stuck or the extruder is clogged. After troubleshooting, click the \"Retry\" button."),
            Map.entry("07018013", "Timeout purging old filament: Please check if the filament is stuck or the extruder is clogged. After troubleshooting, click the \"Retry\" button."),
            Map.entry("07028013", "Timeout purging old filament: Please check if the filament is stuck or the extruder is clogged. After troubleshooting, click the \"Retry\" button."),
            Map.entry("07038013", "Timeout purging old filament: Please check if the filament is stuck or the extruder is clogged. After troubleshooting, click the \"Retry\" button."),
            Map.entry("07FF8001", "Failed to cut the filament. Please check the cutter. After troubleshooting, click the \"Retry\" button."),
            Map.entry("07FF8002", "The cutter is stuck. Please pull out the cutter handle and click the \"Retry\" button."),
            Map.entry("07FF8005", "Failed to feed the filament outside the AMS. Please clip the end of the filament flat and check to see if the spool is stuck. After troubleshooting, click the \"Retry\" button."),
            Map.entry("07FF8010", "AMS assist motor is overloaded. Please check if the spool or filament is stuck. After troubleshooting, click the \"Retry\" button."),
            Map.entry("07FF8011", "AMS filament ran out. Please put a new filament into AMS and click the \"Retry\" button."),
            Map.entry("07FF8013", "Timeout purging old filament: Please check if the filament is stuck or the extruder is clogged. After troubleshooting, click the \"Retry\" button."),
            Map.entry("12008001", "Failed to cut the filament. Please check the cutter. After troubleshooting, click the \"Retry\" button."),
            Map.entry("12018001", "Failed to cut the filament. Please check the cutter. After troubleshooting, click the \"Retry\" button."),
            Map.entry("12028001", "Failed to cut the filament. Please check the cutter. After troubleshooting, click the \"Retry\" button."),
            Map.entry("12008002", "The cutter is stuck. Please pull out the cutter handle and click the \"Retry\" button."),
            Map.entry("12018002", "The cutter is stuck. Please pull out the cutter handle and click the \"Retry\" button."),
            Map.entry("12028002", "The cutter is stuck. Please pull out the cutter handle and click the \"Retry\" button."),
            Map.entry("12008003", "Failed to pull out the filament from the extruder. Please check whether the extruder is clogged or whether the filament is broken inside the extruder. After troubleshooting, click the \"Retry\" button."),
            Map.entry("12018003", "Failed to pull out the filament from the extruder. Please check whether the extruder is clogged or whether the filament is broken inside the extruder. After troubleshooting, click the \"Retry\" button."),
            Map.entry("12028003", "Failed to pull out the filament from the extruder. Please check whether the extruder is clogged or whether the filament is broken inside the extruder. After troubleshooting, click the \"Retry\" button."),
            Map.entry("12008004", "Failed to pull back the filament from the toolhead. Please check whether the filament is stuck. After troubleshooting, click the \"Retry\" button."),
            Map.entry("12018004", "Failed to pull back the filament from the toolhead. Please check whether the filament is stuck. After troubleshooting, click the \"Retry\" button."),
            Map.entry("12008005", "Failed to feed the filament. Please load the filament, then click the \"Retry\" button."),
            Map.entry("12018005", "Failed to feed the filament. Please load the filament and then click the \"Retry\" button."),
            Map.entry("12008006", "Failed to feed the filament into the toolhead. Please check whether the filament is stuck. After troubleshooting, click the \"Retry\" button."),
            Map.entry("12018006", "Failed to feed the filament into the toolhead. Please check whether the filament is stuck. After troubleshooting, click the \"Retry\" button."),
            Map.entry("12008010", "Please check if the spool or filament is stuck. After troubleshooting, click the \"Retry\" button."),
            Map.entry("12018010", "Please check if the spool or filament is stuck. After troubleshooting, click the \"Retry\" button."),
            Map.entry("12008011", "AMS filament has run out. Please insert a new filament into the AMS and click the \"Retry\" button."),
            Map.entry("12018011", "AMS filament has run out. Please insert a new filament into the AMS and click the \"Retry\" button."),
            Map.entry("12008012", "Failed to get AMS mapping table. Please click the \"Retry\" button to continue."),
            Map.entry("12018012", "Failed to get AMS mapping table; please click the \"Retry\" button to continue."),
            Map.entry("12008013", "Timeout while purging old filament. Please check if the filament is stuck or the extruder clogged. After troubleshooting, click the \"Retry\" button."),
            Map.entry("12018013", "Timeout while purging old filament. Please check if the filament is stuck or the extruder clogged. After troubleshooting, click the \"Retry\" button."),
            Map.entry("12008014", "Failed to check the filament location in the tool head, please refer to the HMS. After troubleshooting, click the \"Retry\" button."),
            Map.entry("12018014", "Failed to check the filament location in the tool head, please refer to the HMS. After troubleshooting, click the \"Retry\" button."),
            Map.entry("12028014", "Failed to check the filament location in the tool head, please refer to the HMS. After troubleshooting, click the \"Retry\" button."),
            Map.entry("12038014", "Failed to check the filament location in the tool head; please refer to the HMS. After troubleshooting, click the \"Retry\" button."),
            Map.entry("12008015", "Failed to pull back the filament from the toolhead. Please check if the filament is stuck or the filament is broken inside the extruder. After troubleshooting, click the \"Retry\" button."),
            Map.entry("12018015", "Failed to pull back the filament from the toolhead. Please check if the filament is stuck or the filament is broken inside the extruder. After troubleshooting, click the \"Retry\" button."),
            Map.entry("0300800A", "Purged filaments have piled up in excess chute, which may cause a tool head collision. Please clean the filament. If cleaned or acceptable, tap the resume button to resume the print job."),
            Map.entry("0300800D", "Some objects have fallen down, or the extruder is not extruding normally. If the defects are acceptable, click \"Resume\" button to resume the print job."),
            Map.entry("0C008001", "First layer defects were detected. If the defects are acceptable, click \"Resume\" button to resume the print job."),
            Map.entry("05008030", ""),
            Map.entry("0500402E", "The system does not support the file system currently used by the Micro SD card. Please replace the Micro SD card or format the current Micro SD card to FAT32."),
            Map.entry("0500402F", "The Micro SD card sector data is damaged. Please use the SD card repair tool to repair or format it. If it still cannot be identified, please replace the Micro SD card."),
            Map.entry("05014017", "Binding failed. Please retry or restart the printer and retry."),
            Map.entry("05014018", "Binding configuration information parsing failed,  please try again."),
            Map.entry("05014019", "The printer has already been bound. Please unbind it and try again."),
            Map.entry("0501401A", "Cloud access failed. Possible reasons include network instability caused by interference, inability to access the internet, or router firewall configuration restrictions. You can try moving the printer closer to the router or checking the router configuration and then try again."),
            Map.entry("0501401B", "Cloud response is invalid. If you have tried multiple times and are still failing, please contact customer service."),
            Map.entry("0501401C", "Cloud access is rejected. If you have tried multiple times and are still failing, please contact customer service."),
            Map.entry("0501401D", "Cloud access failed, which may be caused by network instability due to interference. You can try moving the printer closer to the router before you try again."),
            Map.entry("0501401E", "Cloud response is invalid. If you have tried multiple times and are still failing, please contact customer service."),
            Map.entry("0501401F", "Authorization timed out. Please make sure that your phone or PC has access to the internet, and ensure that the Bambu Studio/Bambu Handy APP is running in the foreground during the binding operation."),
            Map.entry("05014020", "Cloud access rejected. If you have tried multiple times and are still failing, please contact customer service."),
            Map.entry("05014021", "Cloud access failed, which may be caused by network instability due to interference. You can try moving the printer closer to the router before you try again."),
            Map.entry("05014022", "Cloud response is invalid. If you have tried multiple times and are still failing, please contact customer service."),
            Map.entry("05014023", "Cloud access rejected. If you have tried multiple times and are still failing, please contact customer service."),
            Map.entry("05014024", "Cloud access failed. Possible reasons include network instability caused by interference, inability to access the internet, or router firewall configuration restrictions. You can try moving the printer closer to the router or checking the router configuration before you try again."),
            Map.entry("05014025", "Cloud response is invalid. If you have tried multiple times and are still failing, please contact customer service."),
            Map.entry("05014026", "Cloud access rejected. If you have tried multiple times and are still failing, please contact customer service."),
            Map.entry("05014027", "Cloud access failed; this may be caused by network instability due to interference. You can try moving the printer closer to the router before you try again."),
            Map.entry("05014028", "Cloud response is invalid. If you have tried multiple times and are still failing, please contact customer service."),
            Map.entry("05014029", "Cloud access is rejected. If you have tried multiple times and are still failing, please contact customer service."),
            Map.entry("05014031", "Device discovery binding is in progress, and the QR code cannot be displayed on the screen. You can wait for the binding to finish or abort the device discovery binding process in the APP/Studio and retry scanning the QR code on the screen for binding."),
            Map.entry("05014034", "The slicing progress has not been updated for a long time, and the printing task has exited. Please confirm the parameters and reinitiate printing."),
            Map.entry("07FF8004", "Failed to pull back the filament from the toolhead to AMS. Please check whether the filament or the spool is stuck. After troubleshooting, click the \"retry\" button."),
            Map.entry("07FFC003", "Please pull out the filament on the spool holder from the extruder or check if there is filament  broken in the extruder, if AMS is to be used later,please connect PTFE tube to the coupler."),
            Map.entry("12FF8003", "Please pull out the filament on the spool holder from the extruder or check if there is filament  broken in the extruder, if AMS is to be used later,please connect PTFE tube to the coupler and click the \"retry\" button."),
            Map.entry("12FFC003", "Please pull out the filament on the spool holder from the extruder or check if there is filament  broken in the extruder, if AMS is to be used later,please connect PTFE tube to the coupler."),
            Map.entry("07FF8003", "Please pull out the filament on the spool holder from the extruder or check if there is filament  broken in the extruder, if AMS is to be used later,please connect PTFE tube to the coupler and click the \"retry\" button."),
            Map.entry("0C00800A", "The detected build plate is not the same as in G-code."),
            Map.entry("12FF8007", "Check nozzle. Click \"Done\" if filament was extruded, otherwise push filament forward slightly and click \"Retry.\""),
            Map.entry("03008006", "Build plate localization marker was not found. Please stop the print job and find the build plate. You can also tap \"Resume\" to force-resume the print job."),
            Map.entry("03008011", "The current build plate is not the same as in G-code. Please stop the print job and replace the build plate. You can also tap \"Resume\" to force-resume the print job."),
            Map.entry("03008012", ""),
            Map.entry("03008013", "Printing was paused by the user. You can tap \"Resume\" to resume the print job."),
            Map.entry("0500402D", "System exception."),
            Map.entry("05004027", "Cloud access failed; this may be caused by network instability due to interference. You can try moving the printer closer to the router before you try again."),
            Map.entry("05004028", "Cloud response is invalid. If you have tried multiple times and are still failing, please contact customer service."),
            Map.entry("05004029", "Cloud access is rejected. If you have tried multiple times and are still failing, please contact customer service."),
            Map.entry("0500402A", "Failed to connect to the router, which may be caused by wireless interference or being too far away from the router. Please try again or move the printer closer to the router and try again."),
            Map.entry("0500402C", "Failed to obtain IP address, which may be caused by wireless interference resulting in data transmission failure or DHCP address pool of the router being full. Please move the printer closer to the router and try again. If the issue persists, please check router settings to see whether the IP addresses have been exhausted."),
            Map.entry("05004016", "The MicroSD Card is write-protected. Please replace the MicroSD Card."),
            Map.entry("0500401A", "Cloud access failed. Possible reasons include network instability caused by interference, inability to access the internet, or router firewall configuration restrictions. You can try moving the printer closer to the router or checking the router configuration and then try again."),
            Map.entry("0500401B", "Cloud response is invalid. If you have tried multiple times and are still failing, please contact customer service."),
            Map.entry("0500401C", "Cloud access is rejected. If you have tried multiple times and are still failing, please contact customer service."),
            Map.entry("0500401D", "Cloud access failed, which may be caused by network instability due to interference. You can try moving the printer closer to the router before you try again."),
            Map.entry("0500401E", "Cloud response is invalid. If you have tried multiple times and are still failing, please contact customer service."),
            Map.entry("05004020", "Cloud access rejected. If you have tried multiple times and are still failing, please contact customer service."),
            Map.entry("05004021", "Cloud access failed, which may be caused by network instability due to interference. You can try moving the printer closer to the router before you try again."),
            Map.entry("05004022", "Cloud response is invalid. If you have tried multiple times and are still failing, please contact customer service."),
            Map.entry("05004023", "Cloud access rejected. If you have tried multiple times and are still failing, please contact customer service."),
            Map.entry("05004024", "Cloud access failed. Possible reasons include network instability caused by interference, inability to access the internet, or router firewall configuration restrictions. You can try moving the printer closer to the router or checking the router configuration before you try again."),
            Map.entry("05004025", "Cloud response is invalid. If you have tried multiple times and are still failing, please contact customer service."),
            Map.entry("05004026", "Cloud access rejected. If you have tried multiple times and are still failing, please contact customer service."),
            Map.entry("0500401F", "Authorization timed out. Please make sure that your phone or PC has access to the internet, and ensure that the Bambu Studio/Bambu Handy APP is running in the foreground during the binding operation."),
            Map.entry("0500402B", "Router connection failed due to incorrect password. Please check the password and try again."),
            Map.entry("05004017", "Binding failed. Please retry or restart the printer and retry."),
            Map.entry("05004018", "Binding configuration information parsing failed,  please try again."),
            Map.entry("05004019", "The printer has already been bound. Please unbind it and try again."),
            Map.entry("07FF8007", "Please observe the nozzle. If the filament has been extruded, click \"Done\"; if it is not, please push the filament forward slightly and then click \"Retry\"."),
            Map.entry("12014001", "Filament is still loaded from the AMS when it has been disabled. Please unload AMS filament, load from spool holder, and restart print job."),
            Map.entry("12024001", "Filament is still loaded from the AMS when it has been disabled. Please unload AMS filament, load from spool holder, and restart print job."),
            Map.entry("12034001", "Filament is still loaded from the AMS when it has been disabled. Please unload AMS filament, load from spool holder, and restart print job."),
            Map.entry("12FF4001", "Filament is still loaded from the AMS when it has been disabled. Please unload AMS filament, load from spool holder, and restart print job."),
            Map.entry("12004001", "Filament is still loaded from the AMS when it has been disabled. Please unload AMS filament, load from spool holder, and restart print job."),
            Map.entry("12FFC006", "Please feed from the spool holder until the tool head filament sensor is triggered."),
            Map.entry("05004015", "There is not enough free storage space for the print job. Please format or clean MicroSD card to release available space."),
            Map.entry("07FFC006", "Please feed from the spool holder until the tool head filament sensor is triggered."),
            Map.entry("0300800E", "The print file is not available. Please check to see if the storage media has been removed."),
            Map.entry("05008013", "The print file is not available. Please check to see if the storage media has been removed."),
            Map.entry("05004014", "Failed to slice the printing job; please check the settings and restart the print job."),
            Map.entry("05004012", "The door seems to be open, so printing was paused."),
            Map.entry("0300800F", "The door seems to be open, so printing was paused."),
            Map.entry("0500C011", ""),
            Map.entry("0500C010", "MicroSD Card error: please reinsert, format or replace it."),
            Map.entry("0500400C", "Please insert a MicroSD card and restart the printing job."),
            Map.entry("07FF8012", "Failed to get AMS mapping table; please click \"Retry\" to continue."),
            Map.entry("07FF4001", "Filament is still loaded from the AMS after it has been disabled. Please unload the filament, load from the spool holder, and restart printing."),
            Map.entry("07FF8006", "Please feed from the spool holder until the tool head filament sensor is triggered, and then click \"Retry\"."),
            Map.entry("0300800C", "Skipping step detected, auto-recover complete; please resume print and check if there are any layer shift problems."),
            Map.entry("0500400E", "Printing was cancelled."),
            Map.entry("0C008009", "Build plate localization marker was not found."),
            Map.entry("0500400D", "Please run a self-test and restart the printing job."),
            Map.entry("0500400B", "There was a problem downloading a file. Please check you network connection and resend the printing job."),
            Map.entry("03008005", "Printing was paused because the front cover of tool head fell off. Please mount it back and tap \"Resume\" to resume the print job."),
            Map.entry("0300400A", "Mechanical resonance frequency identification failed."),
            Map.entry("03008002", "First layer defects were detected. If the defects are acceptable, tap \"Resume\" to resume the print job."),
            Map.entry("03008008", "Nozzle temperature malfunction."),
            Map.entry("03008009", "Heatbed temperature malfunction."),
            Map.entry("0C008005", "Purged filament has piled up in the excess chute, which may cause a tool head collision."),
            Map.entry("0C00C006", "Purged filament may have piled up in the excess chute."),
            Map.entry("0300400E", "The motor self-check failed."),
            Map.entry("0300800B", "The cutter is stuck. Please pull out the cutter handle and click the resume button."),
            Map.entry("07008012", "Failed to get AMS mapping table; please click \"Retry\" to continue."),
            Map.entry("07018012", "Failed to get AMS mapping table; please click \"Retry\" to continue."),
            Map.entry("07028012", "Failed to get AMS mapping table; please click \"Retry\" to continue."),
            Map.entry("07038012", "Failed to get AMS mapping table; please click \"Retry\" to continue."),
            Map.entry("07004001", "Filament is still loaded from the AMS after it has been disabled. Please unload the filament, load from the spool holder, and restart printing."),
            Map.entry("07014001", "Filament is still loaded from the AMS after it has been disabled. Please unload the filament, load from the spool holder, and restart printing."),
            Map.entry("07024001", "Filament is still loaded from the AMS after it has been disabled. Please unload the filament, load from the spool holder, and restart printing."),
            Map.entry("07034001", "Filament is still loaded from the AMS after it has been disabled. Please unload the filament, load from the spool holder, and restart printing."),
            Map.entry("0C008002", "Spaghetti failure was detected."),
            Map.entry("0C00C003", "Possible defects were detected in the first layer."),
            Map.entry("0C00C004", "Possible spaghetti failure was detected."),
            Map.entry("05004007", "Print jobs are not allowed to be sent while force updating or when repair updating is required."),
            Map.entry("05004008", "Starting printing failed. please power cycle the printer and resend the print job."),
            Map.entry("05004009", "Print jobs are not allowed to be sent while updating logs."),
            Map.entry("0500400A", "The file name is not supported. Please rename and restart the printing job."),
            Map.entry("03008001", "Printing was paused by the user. You can tap \"Resume\" to resume the print job."),
            Map.entry("03008003", "Spaghetti defects were detected. If the defects are acceptable, tap \"Resume\" to resume the print job."),
            Map.entry("03008004", "The filament ran out. Please load new filament in Temperature/Axis and tap \"Resume\" to resume the print job."),
            Map.entry("05004001", "Failed to connect to Bambu Cloud. Please check your network connection."),
            Map.entry("05004003", "There was a problem parsing gcode.3mf. Please resend the printing job."),
            Map.entry("05004004", "Printing jobs are not allowed to be sent while printing."),
            Map.entry("05004005", "Print jobs are not allowed to be sent while updating firmware."),
            Map.entry("05004006", "There is not enough free storage space for the print job. Restoring to factory settings can release available space."),
            Map.entry("03008007", "There was an unfinished print job when the printer powered off. Tap \"Resume\" to resume the print job."),
            Map.entry("03004000", "Homing Z axis failed."),
            Map.entry("03004001", "The printer timed out waiting for the nozzle to cool down before homing."),
            Map.entry("03004002", "Mesh bed leveling failed."),
            Map.entry("03004006", "The nozzle is clogged."),
            Map.entry("03004008", "The AMS failed to change filament."),
            Map.entry("03004009", "Homing XY axis failed."),
            Map.entry("0300400B", "Internal communication exception."),
            Map.entry("0300400C", "Printing was cancelled."),
            Map.entry("0300400D", "Resume failed after power loss."),
            Map.entry("03008000", "Printing was paused for unknown reason. You can tap \"Resume\" to resume the print job."),
            Map.entry("03004003", "Nozzle temperature malfunction."),
            Map.entry("3004004", "Heatbed temperature malfunction.")
    );

    public static String intToHex(final int integer) {
        final String result = Integer.toHexString(integer).toUpperCase();
        if (result.length() % 2 == 0) {
            return result;
        }
        return "0%s".formatted(result);
    }

    public static Optional<String> getPrinterError(final String printerError) {
        return Optional.ofNullable(PRINTER_ERRORS.get(printerError));
    }
    public static Optional<String> getPrinterError(final int printerError) {
        return getPrinterError(intToHex(printerError));
    }

}
